import type {VxeGridProps} from "#/adapter/vxe-table";
import {requestClient} from "#/api/request";
import {type FormSchema} from '#/../../../packages/@core/ui-kit/form-ui/src/types'
import {ref} from "vue";


export const tableConfig:VxeGridProps={
  height:'100%',
  columns:[
    {type:"seq",width:70},
    {field:'appCategoryName',title:'分类名称',treeNode: true},
    {field:'sort',title:'排序'},
    {title:'操作',slots:{default:'option'}},
  ],
  treeConfig: {
    parentField: 'pid',
    rowField: 'id',
    hasChildField: 'hasChild',
    lazy:true,
    loadMethod: async ({row})=> {
      return await requestClient.get('/platform/app-category/list_by_pid',{params: {pid:row.id}})
    }
  },
  pagerConfig:{
    enabled:false
  },
  proxyConfig:{
    ajax:{
      query:async ()=>{
        const data = await requestClient.get('/platform/app-category/list_by_pid',{params: {pid:0}});
        data.forEach((i:any)=>i.hasChild=true)
        return data
      }
    }
  }
}
export const p_options=ref<any[]>([{value:"0",label:'顶级'}])
export const form_schema:FormSchema<any>[]=[
  {
    fieldName:'appCategoryName',
    component:'Input',
    label:'应用名称',
    rules:'required',
  },
  {
    fieldName:'sort',
    component:'InputNumber',
    label:'排序',
    defaultValue:1,
    componentProps:{
      min:0
    }
  },
  {
    fieldName:'pid',
    component:'Select',
    label:'上一级',
    componentProps:{
      remote:true,
      filterable:true,
      options:p_options,
    }
  }
]
